def xtree(data):
    if len(data) <= 0:
        return data
    dict = {}
    list = []
    for i in data:
        i['label'] = i['name']
        dict[i['id']] = i
    # 二次遍历
    for j in data:
        # 判断父id是否为0
        pid = j['pid']
        if pid == 0:
            list.append(j)
        else:
            # 子类
            # 看父类下有没有元素，有直接加入列表
            # 没有创建空列表
            if 'children' not in dict[pid]:
                dict[pid]['children'] = []
            dict[pid]['children'].append(j)
    return list